package com.xrui.hbaseview.data;

import java.io.Serializable;

/**
 * This class represents a column with type.
 */
public class TypedColumn implements Serializable {
    //region Constants
    public final static TypedColumn KEY = new TypedColumn("RowKey", ColumnType.BinaryString);
    public final static TypedColumn COLUMN_NAME = new TypedColumn("ColumnName", ColumnType.BinaryString);
    public final static TypedColumn TIMESTAMP = new TypedColumn("Timestamp", ColumnType.DateAsLong);
    //endregion

    //region Variables
    private static final long serialVersionUID = 6851349495766799695L;

    private String name;
    private ColumnType type;
    //endregion

    //region Constructor
    public TypedColumn(String name, ColumnType type) {
        this.name = name;
        this.type = type;
    }
    //endregion

    //region Public Methods
    public static boolean isKey(String name) {
        return KEY.getName().equalsIgnoreCase(name);
    }

    //region Public Properties
    public String getName() {
        return this.name;
    }

    public ColumnType getType() {
        return type;
    }

    public void setType(ColumnType type) {
        this.type = type;
    }

    public boolean isKey() {
        return KEY.equals(this);
    }

    public boolean isColumnName() {
        return COLUMN_NAME.equals(this);
    }

    public boolean isTimestamp() {
        return TIMESTAMP.equals(this);
    }

    @Override
    public String toString() {
        return getName();
    }

    @Override
    public boolean equals(Object obj) {
        return obj instanceof TypedColumn && this.toString().equals(obj.toString());
    }

    @Override
    public int hashCode() {
        return this.toString().hashCode();
    }
    //endregion
}
